package com.ynny.chapter01.controller;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Servlet的开发流程
 * 1.在 pom.xml 引入 servlet依赖
 * 2.新建一个类 继承 HttpServlet -----》实现了 Servlet 接口
 * 3.重写父类的 service()
 * 4.删除父类自带super.service()
 * 5.@WebServlet(value = "/请求路径")
 */

@WebServlet(value = "/login")
public class LoginServlet extends HttpServlet {

    /**
     *
     * @param request  规定了一套 获取请求的方法
     * @param response 规定了一套 响应数据的方法
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {

        System.out.println("LoginServlet~~~~~~~~~~");

        String userName = request.getParameter("username");
        String password = request.getParameter("pwd");

        System.out.println(userName);
        System.out.println(password);

        // 1. 判断用户名和密码是否正确
        // 2. 模拟去数据库中查询用户名和密码是否正确


        if (userName.equals("admin") && password.equals("123")) {
            System.out.println("登陆成功 success ~~~~~~~");
        }else {
            System.out.println("登陆失败 fail ~~~~~~~");
        }





    }
}
